package leetcode;

/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q0198.java
 * @Author : WangRuoyu
 * @Date 2023/2/22 10:57
 */
public class Q0198 {
    public int rob(int[] nums) {
        int[] f = new int[nums.length + 2];
        for (int i = 0; i < nums.length; i++) {
            f[i + 2] = Math.max(f[i + 1], nums[i] + f[i]);
        }
        return f[f.length - 1];
    }

    public static void main(String[] args) {
        Q0198 sl = new Q0198();
        int[] nums = {1, 2, 3, 1};
        System.out.println(sl.rob(nums));
    }
}